<?php
	header('Content-type: application/json');
	session_start();
    error_reporting(0);
	if(isset($_POST['request'])) 
	{
 	  $obj = json_decode($_POST['request']);
	  $response = "success";
	  $link = mysql_connect('localhost','itridio','123456789') or die(jsonEncode('Cannot connect to the DB'));
	  
	  mysql_select_db('itridio',$link) or die(jsonEncode('Cannot select the DB'));
	  $query = "INSERT INTO container (sessionid, latitude, longitude, altitude) VALUES ('".session_id()."','".$obj->{'latitude'}."','".$obj->{'longitude'}."','".$obj->{'altitude'}."')";  
	  mysql_query($query,$link) or die(jsonEncode('Errant query:  '.$query));
	  @mysql_close($link);
	  echo jsonEncode('success');  
	}
	else echo jsonEncode('The POST is null!');  

	function jsonEncode($response)
	{
		$response = array('response' => $response);
		return json_encode($response);
	}

?>